//获取Token参数
var Request = new Object();
Request = GetRequest();
var token = Request['Token'];

//当前页面项目级数
var chargeLevel = 0;
//当前页面单位级数
var deptLevel = 0;
//当前页面项目编码
var chargeCode = '';
//当前页面单位编码
var deptCode = '';
//起始日期
var BngDate='';
//终止日期
var EndDate='';
//服务地址
var basePath = '';
var isReCols='';
var steps;
var stepIndex=-1;
var startStep;
//图型条件
var dCode='';
var cCode='';
var cName='';
var dName='';
//记时
var tr;
var to;
var mId;
var isCanHide;

//饼图数据
	var qtiplist=[];
	var xTitle='';
	var TuTitle='';
	
	$('.mb').hide();
	$('.datagrid-sort-icon').hide();
//	var gridHeight=$('#center').css('height');
//	$('#grid').css('height',gridHeight-2);	
	
$(document)
		.ready(function() {
			isReCols=$("#isReCols").attr("value");
			basePath = $("#basePath").attr("value");
			BngDate = $("#BgnDate").attr("value");
			EndDate = $("#EndDate").attr("value");
			stepIndex=$("#stepIndex").attr("value");
			$("#dateStart").datebox('setValue',BngDate);
			$("#dateEnd").datebox('setValue',EndDate);
			
			$('#mBack').splitbutton({  
		        menu: '#mHistory'  
		    });
			
			if(isReCols='Y'){
			chargeLevel = $("#ChargeLevel").attr("value");
			chargeCode = $("#ChargeCode").attr("value");
			deptLevel = $("#DeptLevel").attr("value");
			deptCode = $("#DeptCode").attr("value");
			$("#isReCols").attr("value","");
			}
			
			//网格
				var grid = $('#grid')
						.datagrid(
								{   
							                striped : true,
											width:'auto',
											height:'auto',
											fit:true,
											nowrap: false,
											striped: true,
											collapsible : false,
											singleSelect:true,
										    showFooter:true,										    
									url : 'action/report/deptcharge/list.json?Token='
											+ token
											+ '&chargeCode='
											+ chargeCode
											+ '&chargeLevel='
											+ chargeLevel
											+ '&deptLevel='
											+ deptLevel
											+ '&deptCode='
											+ deptCode
											+ '&stepIndex='
											+ stepIndex
											+ '&dateStart='+$("#dateStart").datebox('getValue')
										    + '&dateEnd='+$("#dateEnd").datebox('getValue')
											+ '&rnd='
											+ Math.random(),
									sortName : 'DEPTCODE',
									sortOrder : 'asc',
									remoteSort : false,
									idField : 'DEPTCODE',
											pagination:true,
											rownumbers:true,
									onBeforeLoad:function(param){
										
									    $('.mb').hide();
										$('.datagrid-sort-icon').hide();	
										
										$("div.datagrid-header-inner>table").find("td[field='DEPTNAME']").css('background-image','url(images/deptChrgTitle.gif)');
										$("div.datagrid-header-inner>table").find("td[field='DEPTNAME']").css('width','139px');
//										$("div.datagrid-header-inner>table").find("td[field='DEPTNAME']").css('height','56px');
										$("div.datagrid-header-inner>table").find("td[field='DEPTNAME']").css('background-position','left -59px');
										
									},		
									onLoadSuccess : function(data) {
										//显示所有列
										var fields=grid.datagrid('getColumnFields');
										$(fields).each(function(i){
											var col=fields[i];
								        	$('#grid').datagrid('showColumn',col);
										});

										chargeLevel = data.chargeLevel;
										deptLevel = data.deptLevel;
										chargeCode = data.chargeCode;
										deptCode = data.deptCode;
										//设置足迹
										steps=data.steps;
										showSteps(steps);
										
										//绑定下拉菜单
										$('.mb').menubutton({  
                                          menu: '#mm'  
                                          });
										$('#amt').menubutton({  
	                                          menu: '#mm'  
	                                          });
										$('.mb').hide();
										//绑定按钮
										$('.btn').linkbutton({  
                                          plain:true  
                                          });

										//网格头点击事件
										$(".col").bind(
														"click",
														function() {
															var isLeaf=$(this).attr("isLeaf");
															var colName=$.trim($(this).text());
															var chrgCode=$(this).attr("name");
															if (chrgCode!=null&&chrgCode.length!=0&&isLeaf!='1') {
																chrgCode=chargeCode;
																chargeCode = $(this).attr("name");
																chargeLevel = 1 + chargeLevel;
															  $.getJSON('action/report/deptcharge/isHasNext.json?Token=' + token+'&chargeCode='
																						+ chargeCode
																						+ '&chargeLevel='
																						+ chargeLevel
																						+ '&deptLevel=' + deptLevel
																						+ '&deptCode=' + deptCode
																						+ '&isReCols=Y'
																						+ "&rnd=" + Math.random(),function(data){
																							if(data.gridCols.length>0){
																window.location.href = basePath
																		+ 'action/report/deptcharge/loadPage.do?Token=' + token+'&chargeCode='
																		+ chargeCode + '&chargeLevel='
																		+ chargeLevel + '&deptLevel=' + deptLevel
																		+ '&deptCode=' + deptCode 
																		+ '&isReCols=Y'
																		+ '&colName='+encodeURI(colName)
																		+ '&dateStart='+$("#dateStart").datebox('getValue')
																	    + '&dateEnd='+$("#dateEnd").datebox('getValue')
																		+ "&rnd="+ Math.random();
																}else{
																	chargeLevel=chargeLevel-1;
																	chargeCode=chrgCode;
																}
														     });
															}
										});
										//隐藏空列
										var ftr=data.ftr;
										hideEmptyCol(ftr);
										
										$('.datagrid-sort-icon').hide();
										
										//记录足迹
										stepIndex=data.stepIndex;
										showSteps(steps);
										
										$('div.datagrid-view2>div.datagrid-body').css('overflow','hidden');
										
										//绑定列拖动事件
										$('#grid').datagrid("columnMoving");
										fcolIndex=-1;
										fnum=-1;
									},
									onAfterRender:function(){
										$(".pagination-info").css('visibility',false);
										$(".pagination-info").hide();
										$(".pagination-info").empty();
										$(".pagination-info").remove();
									},
									onLoadError:function(){
										
												return false;
										
									},
									onClickCell : function(rowIndex, field,
											value) {
										$('#grid').datagrid('selectRow',
												rowIndex);
										var select = $('#grid').datagrid(
												'getSelected');
										//点击单位列
										if (field == 'DEPTNAME') {
											var rowName = select.DEPTNAME;
											if(select.DEPTLEAF!=1){
												deptLevel = 1 + deptLevel;
												deptCode = select.DEPTCODE;
												$('#grid').datagrid("options").pageNumber = 1;
												$('#grid')
														.datagrid(
																{
																	url : 'action/report/deptcharge/list.json?Token='
																			+ token
																			+ '&chargeCode='
																			+ chargeCode
																			+ '&chargeLevel='
																			+ chargeLevel
																			+ '&deptLevel='
																			+ deptLevel
																			+ '&deptCode='
																			+ deptCode,
																	'queryParams' : {
																		'rowName':rowName,
																	    'dateStart':$("#dateStart").datebox('getValue'),
																	    'dateEnd':$("#dateEnd").datebox('getValue'),
																		'rnd' : Math
																				.random()	
																	}
																});
											}
										} else {//点击其他单元合格

											var chrgLeaf=$('#m_' + field).attr(
											"isLeaf");
											var colName=$.trim($('#m_' + field).text());
											var chrgCode=chargeCode;
											var dptCode=deptCode;
											var rowName=select.DEPTNAME;
											if((chrgLeaf!='1'||select.DEPTLEAF!='1')&&value!=0){
												
												chargeCode = $('#m_' + field).attr(
														"name");
												
												deptCode = select.DEPTCODE;
												if(chrgLeaf!='1')
												    chargeLevel = 1 + chargeLevel;
												if(select.DEPTLEAF!='1')
												    deptLevel = 1 + deptLevel;
												$.getJSON('action/report/deptcharge/isHasNext.json?Token=' + token+'&chargeCode='
														+ chargeCode
														+ '&chargeLevel='
														+ chargeLevel
														+ '&deptLevel=' + deptLevel
														+ '&deptCode=' + deptCode
														+ '&isReCols=Y'
														+ "&rnd=" + Math.random(),function(data){
															if(data.gridCols.length>0){
																
																window.location.href = basePath
														+ '/action/report/deptcharge/loadPage.do?Token=' + token+'&chargeCode='
														+ chargeCode
														+ '&chargeLevel='
														+ chargeLevel
														+ '&deptLevel=' + deptLevel
														+ '&deptCode=' + deptCode
														+ '&isReCols=Y'
														+ '&colName='+encodeURI(colName)
														+ '&rowName='+encodeURI(rowName)
														+ '&dateStart='+$("#dateStart").datebox('getValue')
														+ '&dateEnd='+$("#dateEnd").datebox('getValue')
														+ "&rnd=" + Math.random();
															}else
																if(chrgLeaf!='1')
																   chargeLevel=chargeLevel-1;
															    if(select.DEPTLEAF!='1')
															       deptLevel=deptLevel-1;
															    deptCode=dptCode;
															    chargeCode=chrgCode;
														});
											}
										}

									}
								});
				
		$('#queryDept').combotree({
		url :'action/basic/depart/tree.json?Token=' + token,
		editable:false,
		panelWidth:'300',
		onClick: function(node)
		{
			$("#queryDept").val(node.text);
		},
		onDblClick: function(node)
		{
			$(this).tree('toggle', node.target);
			$("#queryDept").val(node.text);
		},onShowPanel:function()
		{
			$(this).combotree('panel').parent('.panel').css('border-bottom','#87cedb 3px solid');
			$(this).combotree('panel').parent('.panel').css('border-left','#87cedb 3px solid');
			$(this).combotree('panel').parent('.panel').css('border-right','#87cedb 3px solid');
		}
});
		$('.mb').hide();
		$('.datagrid-sort-icon').hide();
		$('.fieldName').css('display','block');
		$('.fieldName').css('padding','1px');
		
		$('.panel-title').css(' vertical-align','middle');
		$('.panel-tool').css('padding-right','10px');
		$('.panel-tool').prepend('<a id="windowClose" style="height:24px;filter:alpha(opacity=60);WIDTH: 32px;" iconCls="icon-no" onclick=closeWin() />');
		$('.panel-tool').prepend('<a id="panelPie" style="height:24px;filter:alpha(opacity=60);WIDTH: 32px;" iconCls="icon-pie"/ onclick=changeTu("pie") />');
		$('.panel-tool').prepend('<a id="panelBar" style="height:24px;filter:alpha(opacity=60);WIDTH: 32px;" iconCls="icon-bar"/ onclick=changeTu("bar") />');
		$('.panel-tool').prepend('<a id="panelLine" style="height:24px;filter:alpha(opacity=60);WIDTH: 32px;" iconCls="icon-line" onclick=changeTu("line") />');
		$('#windowClose').linkbutton({  
		});  
		$('#panelPie').linkbutton({  
		});  
		$('#panelBar').linkbutton({  
		});  
		$('#panelLine').linkbutton({  
		});  
		
		$("div.datagrid-header-inner>table").find("td[field='DEPTNAME']").css('background-image','url(images/deptChrgTitle.gif)');
		$("div.datagrid-header-inner>table").find("td[field='DEPTNAME']").css('width','139px');
//		$("div.datagrid-header-inner>table").find("td[field='DEPTNAME']").css('height','56px');
		$("div.datagrid-header-inner>table").find("td[field='DEPTNAME']").css('background-position','left -59px');
});
//条件按条件查询
function queryList() {
	var startDate = $("#dateStart").datebox('getValue');
    var endedDate =  new Date($("#dateEnd").datebox('getValue').replace(/-/g,"/"));
    if(startDate){
    	var beginDate =  new Date(startDate.replace(/-/g,"/"));
		if(beginDate > endedDate){
			$.messager.alert('消息','起始日期不能大于结束日期');
			return false;
		}
    }
	
    deptCode=$("#queryDept").val();
    var rName='';
	if (deptCode!=null&&deptCode.length>0){
	    rName=deptCode.substring(1+deptCode.indexOf(']',0),deptCode.length);
	    deptCode=deptCode.substring(1+deptCode.indexOf('[',0),deptCode.indexOf(']',0));
	}
	$('#grid').datagrid("options").pageNumber = 1;
	$('#grid')
			.datagrid(
					{
						url : 'action/report/deptcharge/list.json?Token='
								+ token
								+ '&chargeCode='
								+ chargeCode
								+ '&chargeLevel='
								+ chargeLevel
								+ '&deptCode=' + deptCode,
						'queryParams' : {
						    'isQuery':"Y",
						    'dateStart':$("#dateStart").datebox('getValue'),
						    'dateEnd':$("#dateEnd").datebox('getValue'),
						    'rowName':'单位：'+rName+'日期：'+$("#dateStart").datebox('getValue')+'<'+$("#dateEnd").datebox('getValue'),
 							'rnd' : Math
									.random()
						}
					});
}

//把信息放入回复留言页面
function inputdata(data) {
	$("#txtuser").val(data.F_USER);
	$("#txtpwd").val(data.F_PWD);
	$("#txtmemo").val(data.F_MEMO);
	$("#txtid").val(data.F_ID);
	if (data.F_TYPE == "2")
		$("#rdono").attr("checked", "true");
	else
		$("#rdoyes").attr("checked", "true");
}
//鼠标悬停图标按钮时触发
function onmonse(chgCode,chgName,dptRow){

	       cCode=chgCode;
	       cName=chgName;
	       isCanHide=1;
	       if(dptRow!=null&&dptRow.length!=0){
	    	   $('#grid').datagrid('selectRow',dptRow);
			   var select = $('#grid').datagrid('getSelected');
			   dCode=select.DEPTCODE;
			   dName=select.DEPTNAME;
			   $('#grid').datagrid('unselectAll');
	       }
	       isCanHide=false;
}

function pieShow(type){
	
	var iUrl='';
	var title='';
	var xName='';
	var btData = 'Y' ;
	if(cCode!=null&&cCode.length!=0){
	    iUrl='action/report/deptcharge/getQtip.json?Token='+ token+'&groupType=charge&chargeCode='+cCode+'&deptLevel='+deptLevel+'&deptCode='+deptCode+ '&dateStart='+$("#dateStart").datebox('getValue')
		+'&dateEnd='+$("#dateEnd").datebox('getValue');
	    title=cName;
	    xName='单位';
	}
	else if(dCode!=null&&dCode.length!=0){
	    iUrl='action/report/deptcharge/getQtip.json?Token='+ token+'&groupType=dept&deptCode='+dCode+'&chargeLevel='+chargeLevel+'&chargeCode='+chargeCode+ '&dateStart='+$("#dateStart").datebox('getValue')
		+ '&dateEnd='+$("#dateEnd").datebox('getValue');
	    title=dName;
	    xName='项目';
	}
	else{
		iUrl='action/report/deptcharge/getQtip.json?Token='+ token+'&groupType=dept&chargeLevel='+chargeLevel+'&chargeCode='+chargeCode+'&deptLevel='+deptLevel+'&deptCode='+deptCode+'&dateStart='+$("#dateStart").datebox('getValue')
		+ '&dateEnd='+$("#dateEnd").datebox('getValue');
	    title='合计';
	    xName='项目';
	}
	if(iUrl!=null&&iUrl.length!=0){
		$.getJSON(iUrl+'&rnd='+ Math.random(),function(data){
				qtiplist=data.qtipData;
				if(qtiplist.length>0){
					if(type=='pie')
                    {
						for(i=0 ;i<qtiplist.length;i++)
						{
						    if(qtiplist[i].value<0)
						    {						    	
						    	btData = 'N' ;
						    	break ;
						    }	
						}
						if(btData=='Y')
				    		pie(title,xName)
				    	else
				    		$.messager.alert('提示',"<h5>含有负数数据，不能生成饼图!</h5>");
                    }	
					if(type=='bar')
					  bar(title,xName);
					if(type=='line')
					  line(title,xName);	
				}
		});
	}
	cCode='';	
	dCode='';
}
//格式化一般列
var fcolIndex=-1;
var fnum=-1;
function formater(value, row, index) {
    if(index=fnum){
    	++fcolIndex;
    }else{
    	fcolIndex=0;
    	fnum=index;
    }
    	
	var d=fmoney(value,2);
	var cols= $('#grid').datagrid('getColumnFields');
	var colName=cols[fcolIndex];
	if(row.DEPTNAME!='合计'){
		var colIsLeaf=$('#m_' + colName).attr("isLeaf");
		var rowIsLeaf=row.DEPTLEAF;
		if(colIsLeaf==0||rowIsLeaf==0){
	        d = "<a href='javascript:void(0)' title='点击查看详细信息'>" + fmoney(value,2) + "</a>";
		}
	}
	return d;

}
//格式化锁定列
function formatFozen(value, row, index) {
   
	var str='"onmonse('+"''"+','+"''"+','+"'"+(index)+"'"+')"';
	var d ="";
	var id=row.ROWNUM_-1+"_"+index;
	if(row.DEPTLEAF!=null&&row.DEPTLEAF=='1')
		d ="<table style='border-width: 0px;width:100%;padding:0px;' onmouseover=showMenu('"+id+"') ><tr style='border-width: 0px' ><td style='border-width: 0px'><a style='float:left;'>"+value+ "</a></td><td style='border-width: 0px;width:30px;'><a style='float:right;' id="+id+" style='visibility:false;' href='javascript:void(0)' class='mb' onmouseover="+str+" ></a></td></tr></table>";
	else	
	    d = "<table style='border-width: 0px;width:100%;padding:0px;' onmouseover=showMenu('"+id+"') ><tr style='border-width: 0px'><td style='border-width: 0px'><a style='float:left;' href='javascript:void(0)' title='点击查看详细信息'>" + value + "</a></td><td style='border-width: 0px;width:30px;'><a  id="+id+" style='visibility:false;float:right;' href='javascript:void(0)' class='mb' onmouseover="+str+" ></a></td></tr></table>";
	if(value=='合计'){
		d="合计<a href='javascript:void(0)' id='amt' onmouseover='PbtnOnmover()' onclick="+'pieShow('+'"pie"'+')'+"></a>";
	}
	return d;

}
//鼠标离开图标按钮时触发
function PbtnOnmover(){
	cCode='';
	dCode='';
}

//饼图
function pie(title,xName)
{
	
	var char = {};
	xName=xTitle;
	TuTitle=title;
	char["xAxisName"]=xName;
	char["yAxisName"] = "收入";
	char["caption"] = title;
	char["numberprefix"] = "￥";
	char["showborder"] = "1";
	char["numberScaleUnit"]="千,百万,十亿,万亿";
	var data = [qtiplist];
	var json ={};	
	json["chart"]=char;
	json["data"]=data;
	//alert(char.yaxisname);
	$('#pie').window('open');
	$('#pie').window('maximize');
	var h=$('#outSide').height();
	var w=$('#outSide').width();
	$('#pie').css('width',w-5);
	$('#pie').css('height',h-46);
	$("div[class*='window']").not('.window-mask').css('width',w-5);
	$('.window-shadow').css('height',h-46);

	var myChart = new FusionCharts("javascript/fusioncharts/Pie2D.swf", "asdf", "100%", "100%", "0", "1");

    myChart.setJSONData(json);
    myChart.render("pie");
    
}

//柱状图
function bar(title,xName)
{
	var char = {};
	xName=xTitle;
	TuTitle=title;
	char["xAxisName"]=xName;
	char["yAxisName"] = "收入";
	char["caption"] = title;
	char["numberprefix"] = "￥";
	char["showborder"] = "1";
	char["numberScaleUnit"]="千,百万,十亿,万亿";
	var data = [qtiplist];
	var json ={};
	json["chart"]=char;
	json["data"]=data;

	$('#pie').window('open');
	$('#pie').window('maximize');
	var h=$('#outSide').height();
	var w=$('#outSide').width();
	$('#pie').css('width',w-5);
	$('#pie').css('height',h-46);
	$("div[class*='window']").not('.window-mask').css('width',w-5);
	$('.window-shadow').css('height',h-46);

	var myChart = new FusionCharts("javascript/fusioncharts/Column3D.swf", "asdf", "100%", "100%", "0", "1");

    myChart.setJSONData(json);
    myChart.render("pie");
}

//柱状图
function line(title,xName)
{
	var char = {};
	xName=xTitle;
	TuTitle=title;
	char["xAxisName"]=xName;
	char["yAxisName"] = "收入";
	char["caption"] = title;
	char["numberprefix"] = "￥";
	char["showborder"] = "1";
	char["numberScaleUnit"]="千,百万,十亿,万亿";
	var data = [qtiplist];
	var json ={};
	json["chart"]=char;
	json["data"]=data;

	$('#pie').window('open');
	$('#pie').window('maximize');
	var h=$('#outSide').height();
	var w=$('#outSide').width();
	$('#pie').css('width',w-5);
	$('#pie').css('height',h-46);
	$("div[class*='window']").not('.window-mask').css('width',w-5);
	$('.window-shadow').css('height',h-46);

	var myChart = new FusionCharts("javascript/fusioncharts/Line.swf", "asdf", "100%", "100%", "0", "1");

    myChart.setJSONData(json);
    myChart.render("pie");
}

//切换图像方法
function changeTu(title){
	var char = {};
	var btData = 'Y' ;
	char["xAxisName"]=xTitle;
	char["yAxisName"] = "收入";
	char["caption"] = TuTitle;
	char["numberprefix"] = "￥";
	char["showborder"] = "1";
	char["numberScaleUnit"]="千,百万,十亿,万亿";
	var data = [qtiplist];
	var json ={};
	json["chart"]=char;
	json["data"]=data;

    if(title=='line')
	    var myChart = new FusionCharts("javascript/fusioncharts/Line.swf", "asdf", "100%", "100%", "0", "1");
    else if(title=='pie')
    {
		
			for(i=0 ;i<qtiplist.length;i++)
			{
			    if(qtiplist[i].value<0)
			    {						    	
			    	btData = 'N' ;
			    	break ;
			    }	
			}
			if(btData=='Y')
	    		var myChart = new FusionCharts("javascript/fusioncharts/Pie2D.swf", "asdf", "100%", "100%", "0", "1");
	    	else
	    		$.messager.alert('提示',"<h5>含有负数数据，不能生成饼图!</h5>");
        	
    }	    	
    else if(title=='bar')	
    	var myChart = new FusionCharts("javascript/fusioncharts/Column3D.swf", "asdf", "100%", "100%", "0", "1");
    
    myChart.setJSONData(json);
    myChart.render("pie");
}

//日期验证
//$.extend($.fn.validatebox.defaults.rules, { 
//    checkDateBegin:{
//    	validator: function(value, param){
//		    var selectDate =  new Date(value.replace(/-/g,"/"));
////		    return 
//		    if(selectDate <= new Date())
//		    	alert('起始日期不能大于当天日期');
//		},
//		message: ''
//    },
//    checkDateEnd:{
//    	validator: function(value, param){
//    		var startDate = $("#"+param[0]).datebox('getValue');
//		    var endedDate =  new Date(value.replace(/-/g,"/"));
//		    var result = true;
//		    if(startDate){
//		    	var beginDate =  new Date(startDate.replace(/-/g,"/"));
//				if(beginDate <= endedDate)
//					alert('起始日期不能大于终止日期')
//		    }
//		    
//		},
//		message: ''
//    }
//
//});
//查询栏可视属性修改
function showQryPnl(type){
	if(type=='show'){
		$("#toolPnl").css('display','none');
		$("#toolPnl").hide('slow');
		$("#queryPnl").show('slow');
	}else if(type=='hide'){
		$("#queryPnl").hide('slow');
		$("#toolPnl").show('slow');
	}
}

//生成访问足迹
function showSteps(st){
	if(st!=null&&st.length>0){
		$("#mHistory").empty();
		for(i=(st.length-1);i>-1;i--){
        	var step=st[i];
        	$('#mHistory').menu('appendItem',{id:'step_'+i,text:step.stepName,name:i,
        		handler:function(){
        			var index=this.id.substring(1+this.id.indexOf('_',0),this.id.length);
        			toStep(index);
        		}
        	});
		}
		$('#mHistory').menu('appendItem',{id:'step_-1',text:'首页',
			handler:function(){
				toStep("-1");
			}
		});

	}
	
}

//左右添加足迹
function moveStep(lr){
	var rId=0;
	var aId=0;
	var name="";
	if(lr=='left'){
		if (startStep==0){
			$('#lbtn').hide();
		}else{
		rId=startStep+4;
        aId=startStep-1;
        startStep=startStep-1;
        var step=steps[aId];
    	name=step.stepName;	
    	$("#step_"+rId).remove();
    	$("#step").prepend('<a id="step_'+aId+'" class="step" onclick=toStep("'+aId+'")>'+name+'--></a>');
    	$('#rbtn').show();
		}	
	}
	if(lr=='right'){
		
		if ((startStep+5)>=steps.length){
		     $('#rbtn').hide();
		}else{
		rId=startStep;
        aId=startStep+5;
        startStep=startStep+1;
        var step=steps[aId];
    	name=step.stepName;	
    	$("#step_"+rId).remove();
    	$("#step").append('<a id="step_'+aId+'" class="step" onclick=toStep("'+aId+'")>-->'+name+'</a>');
    	$('#lbtn').show();
		}
	}
	
	if (startStep==0)
		$('#lbtn').hide();
	if ((startStep+5)>=steps.length)
		$('#rbtn').hide();
	
}
//跳转到足迹页面
function toStep(index){
	var rowName='';
	var colName='';
	if(index>=0){
	   var step=steps[index];
	   chargeCode=step.chargeCode;
	   chargeLevel=step.chargeLevel;
	   deptLevel=step.deptLevel;
	   deptCode=step.deptCode;
	   rowName=step.rowName;
	   colName=step.colName;
	}else{
	   chargeCode="";
	   chargeLevel=0;
	   deptLevel=0;
	   deptCode="";
	}	
	var url=basePath
	+ '/action/report/deptcharge/loadPage.do?Token=' + token+'&chargeCode='
	+ chargeCode
	+ '&chargeLevel='
	+ chargeLevel
	+ '&deptLevel=' + deptLevel
	+ '&deptCode=' + deptCode
	+ '&dateStart='+$("#dateStart").datebox('getValue')
	+ '&dateEnd='+$("#dateEnd").datebox('getValue')
	+ '&isReCols=Y&isStep=Y'+'&stepIndex='+index;
	if(rowName!=null&&rowName.length>0)
		url=url+'&rowName='+encodeURI(rowName);
	if(colName!=null&&colName.length>0)
		url=url+'&colName='+encodeURI(colName);
	window.location.href =url;
}
//隐藏无数据列
function hideEmptyCol(ftr){
	if(ftr!=null&&ftr.length>0){
		$(ftr).each(function(i){
	        	var col=ftr[i];
	        	$('#grid').datagrid('hideColumn',col.field);
	});
}
}

//将数字转换成三位逗号分隔的样式 
//格式话金额	
function fmoney(s, n)//将数字转换成逗号分隔的样式,保留两位小数s:value,n:小数位数   
{
	var flag = 1 ;
	rs='';
	if(s!=0)
	{	if(s<0)
		{
			flag = 0 ;
			s=-s;
		}
		n = n > 0 && n <= 20 ? n : 2;
		s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
		var l = s.split(".")[0].split("").reverse(),
		r = s.split(".")[1];
		t = "";
		for(i = 0; i < l.length; i ++ )
		{
		t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
		}
		rs=t.split("").reverse().join("") + "." + r;
	}
	if(flag==0)
		rs="-"+rs;
	return rs;
}
//重置查询条件
function clearQry(){
	$("#queryDept").combotree('setValue','');
	$("#dateStart").datebox('setValue',BngDate);
	$("#dateEnd").datebox('setValue',EndDate);
}
//鼠标悬停单元格显示对应图表按钮
function showMenu(id){
	if(id!=mId)
	   $(".mb").hide('slow');
	$("#"+id).show();
	mId=id;
}
//后退
function back(){
	index=stepIndex-1;
	if(index>=0){
	   var step=steps[index];
	   chargeCode=step.chargeCode;
	   chargeLevel=step.chargeLevel;
	   deptLevel=step.deptLevel;
	   deptCode=step.deptCode;
	}else{
	   chargeCode="";
	   chargeLevel=0;
	   deptLevel=0;
	   deptCode="";
	}	
	var url=basePath
	+ '/action/report/deptcharge/loadPage.do?Token=' + token+'&chargeCode='
	+ chargeCode
	+ '&chargeLevel='
	+ chargeLevel
	+ '&deptLevel=' + deptLevel
	+ '&deptCode=' + deptCode
	+ '&dateStart='+$("#dateStart").datebox('getValue')
	+ '&dateEnd='+$("#dateEnd").datebox('getValue')
	+ '&isReCols=Y&isStep=Y'+'&stepIndex='+index;
	window.location.href =url;
}
//显示滚动条
function showScroll(){
	$('div.datagrid-view2>div.datagrid-body').css('overflow','auto');
}
//隐藏滚动条
function hideScroll(e,o){
	if(o.contains(event.toElement ) == false) 
	    $('div.datagrid-view2>div.datagrid-body').css('overflow','hidden');
}

//列拖动
$.extend($.fn.datagrid.methods,{
	columnMoving: function(jq){
		return jq.each(function(){
			var target = this;
			var cells = $(this).datagrid('getPanel').find('div.datagrid-header td[field]');
			cells.draggable({
				revert:true,
				cursor:'pointer',
				edge:5,
				proxy:function(source){
					var p = $('<div class="tree-node-proxy tree-dnd-no" style="position:absolute;border:1px solid #ff0000"/>').appendTo('body');
					p.html($(source).text());
					p.hide();
					return p;
				},
				onBeforeDrag:function(e){
					e.data.startLeft = $(this).offset().left;
					e.data.startTop = $(this).offset().top;
				},
				onStartDrag: function(){
					$(this).draggable('proxy').css({
						left:-10000,
						top:-10000
					});
				},
				onDrag:function(e){
					$(this).draggable('proxy').show().css({
						left:e.pageX+15,
						top:e.pageY+15
					});
					return false;
				}
			}).droppable({
				accept:'td[field]',
				onDragOver:function(e,source){
					$(source).draggable('proxy').removeClass('tree-dnd-no').addClass('tree-dnd-yes');
					$(this).css('border-left','1px solid #ff0000');
				},
				onDragLeave:function(e,source){
					$(source).draggable('proxy').removeClass('tree-dnd-yes').addClass('tree-dnd-no');
					$(this).css('border-left',0);
				},
				onDrop:function(e,source){
					$(this).css('border-left',0);
					var fromField = $(source).attr('field');
					var toField = $(this).attr('field');
					setTimeout(function(){
						moveField(fromField,toField);
						$(target).datagrid();
						$(target).datagrid('columnMoving');
					},0);
				}
			});
			
			// move field to another location
			function moveField(from,to){
				var columns = $(target).datagrid('options').columns;
				var cc = columns[0];
				var c = _remove(from);
				if (c){
					_insert(to,c);
				}
				
				function _remove(field){
					for(var i=0; i<cc.length; i++){
						if (cc[i].field == field){
							var c = cc[i];
							cc.splice(i,1);
							return c;
						}
					}
					return null;
				}
				function _insert(field,c){
					var newcc = [];
					for(var i=0; i<cc.length; i++){
						if (cc[i].field == field){
							newcc.push(c);
						}
						newcc.push(cc[i]);
					}
					columns[0] = newcc;
				}
			}
		});
	}
});

//不能删哦～
function setIEHeight(tr,height){
	//doNothing
}

function closeWin(){
	$('#pie').window('close');
}